/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
using namespace std;


bool isPrime(int n){
    if(n<=1){
        return false;
    }
    for (int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
int main()
{
    int number;
    cin>>number;
    
    if(number<1000 || number>9999){
        cout<<"0";
        return 1;
    }
    int max=0;
    
    string n=to_string(number);
    int x=n.length();
    
    
    for(int i=0;i<x;++i){
        for(int k=x;k>i;--k){
            int num=stoi(n.substr(i,k-i));
            if(isPrime(num)&&num>max){
                max=num;
            }
        }
    }
    cout<<max;
    return 0;
}
